import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisDemoList {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()){
//            test1(jedis);
            //test2(jedis);
            //test3(jedis);
            test4(jedis);
        }
    }

    private static void test4(Jedis jedis) {
        System.out.println("llen");
        jedis.flushAll();
        jedis.lpush("key1", "111", "222");
        long len = jedis.llen("key1");
        System.out.println(len);
    }

    private static void test3(Jedis jedis) {
        System.out.println("blpop brpop");
        jedis.flushAll();
        jedis.lpush("key1", "111","222","333");
        List<String> list1 = jedis.brpop(10, "key1");
        List<String> list2 = jedis.blpop(10, "key1");
        System.out.println(list1.get(1));
        System.out.println(list2.get(1));
    }

    private static void test2(Jedis jedis) {
        System.out.println("lpop rpop");
        jedis.flushAll();
        jedis.lpush("key1", "111", "222", "333");
        String result = jedis.lpop("key1");
        System.out.println(result);
        result = jedis.rpop("key1");
        System.out.println(result);
        result = jedis.rpop("key1");
        System.out.println(result);
        result = jedis.rpop("key1");
        System.out.println(result);
    }


    private static void test1(Jedis jedis) {
        System.out.println("lpush 和 lrange");
        jedis.flushAll();
        jedis.lpush("key1", "111", "222", "333");//rpush的用法相同
        List<String> list = jedis.lrange("key1", 0, -1);
        System.out.println(list);
    }
}
